package com.sokal.easycare.modules.shares.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.sokal.easycare.common.service.CrudService;
import com.sokal.easycare.common.utils.FastDFS.FastDFSClient;
import com.sokal.easycare.modules.product.entity.product.ProProductFile;
import com.sokal.easycare.modules.shares.dao.ExprShareFileDao;
import com.sokal.easycare.modules.shares.entity.ExperienceSharing;
import com.sokal.easycare.modules.shares.entity.ExprShareFile;

/** 
* 经验分享附件Service
* @author lihaipei
* @date 2017年3月30日 下午1:43:09 
*/
@Service
@Transactional(readOnly = true)
public class ExprShareFileService extends CrudService<ExprShareFileDao, ExprShareFile> {

	public List<ExprShareFile> findList(ExprShareFile exprShareFile) {
		return super.findList(exprShareFile);
	}
	
	@Transactional(readOnly = false)
	public void save (MultipartFile experShareFile, String exprShareId) throws Exception{
		ExperienceSharing experSharing = new ExperienceSharing();
		experSharing.setId(exprShareId);
		
		ExprShareFile exprShareFile = new ExprShareFile();
		exprShareFile.setFileUrl(FastDFSClient.uploadFile(experShareFile, experShareFile.getOriginalFilename()));
		exprShareFile.setFileName(experShareFile.getOriginalFilename());
		exprShareFile.setFileType(ProProductFile.FILE_TYPE_SINGLE_IMAGE);
		exprShareFile.setExprSharing(experSharing);
		
		super.save(exprShareFile);
	}
	
	@Transactional(readOnly = false)
	public void updateSort(ExprShareFile exprShareFile) {
		dao.updateSort(exprShareFile);
	}
	
}
